package com.hiwetop.crawler;

import org.apache.http.HttpHost;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;

/**
 * Created by linyu on 2016/12/12.
 */
public class GithubRepoPageProcessor implements PageProcessor {

    private Site site = Site.me().setRetryTimes(3).setSleepTime(1000).setHttpProxy(new HttpHost("127.0.0.1",1080));

    @Override
    public void process(Page page) {
        page.addTargetRequests(page.getHtml().css("div.pg").links().regex(".*forum\\.php.*").all());
    }

    @Override
    public Site getSite() {
        return site;
    }

    public static void main(String[] args) {
        Spider.create(new GithubRepoPageProcessor()).addUrl("http://0591night.com/forum.php").thread(5).run();
    }
}
